package gongqing.views.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xkh.xkh.R;

import gongqing.network.beans.IrrBDDeviceDetail;
import gongqing.network.http.GetBasicDeviceInfo;
import com.xkh.xkh.MyApplication;
import shuiyuqing.model.BasicInfoModel;
import shuiyuqing.network.beans.IrrBRStadia;

/**
 * 包含设备信息
 * Created by 凯 on 2015/11/15.
 */
public class DeviceAdapter extends BaseAdapter {

    // 基本设备信息
    GetBasicDeviceInfo getBasicDeviceInfo;

    public GetBasicDeviceInfo getGetBasicDeviceInfo() {
        return getBasicDeviceInfo;
    }

    public void setGetBasicDeviceInfo(GetBasicDeviceInfo getBasicDeviceInfo) {
        this.getBasicDeviceInfo = getBasicDeviceInfo;
    }

    @Override
    public int getCount() {
        return getBasicDeviceInfo.getDownload().getDetails().size();
    }

    @Override
    public Object getItem(int position) {
        return getBasicDeviceInfo.getDownload().getDetails().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null)
        {
            convertView = View.inflate(MyApplication.share(), R.layout.item_deviceinfo,null);
            viewHolder = new ViewHolder();
            viewHolder. tv_deviceName = (TextView) convertView.findViewById(R.id.id_tv_devicename);
            viewHolder. tv_devtype = (TextView) convertView.findViewById(R.id.id_tv_devtype);
            viewHolder. tv_manufac = (TextView) convertView.findViewById(R.id.id_tv_manufac);
            viewHolder. tv_state = (TextView) convertView.findViewById(R.id.id_tv_state);
            viewHolder. tv_loc = (TextView) convertView.findViewById(R.id.id_tv_loc);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        IrrBDDeviceDetail irrBDDeviceDetail = getBasicDeviceInfo.getDownload().getDetails().get(position);

//        TextView tv_depart = (TextView) convertView.findViewById(R.id.id_tv_depart);
//        TextView tv_manager = (TextView) convertView.findViewById(R.id.id_tv_manager);
//        TextView tv_price = (TextView) convertView.findViewById(R.id.id_tv_price);
//        TextView tv_purch = (TextView) convertView.findViewById(R.id.id_tv_purch);
//        TextView tv_install = (TextView) convertView.findViewById(R.id.id_tv_install);
//        TextView tv_remark = (TextView) convertView.findViewById(R.id.id_tv_remark);

        viewHolder.tv_deviceName.setText(irrBDDeviceDetail.getDevName().trim());
        viewHolder.tv_devtype.setText(irrBDDeviceDetail.getDevType().trim());
        viewHolder.tv_manufac.setText(irrBDDeviceDetail.getManufacture().trim());
        viewHolder.tv_state.setText(irrBDDeviceDetail.getDevState().trim());

        IrrBRStadia irrBRStadia = BasicInfoModel.getIrrBRStadiaByCode(irrBDDeviceDetail.getLocCode());
        viewHolder.tv_loc.setText(irrBRStadia.getStadiaName());
//        tv_loc.setText(irrBDDeviceDetail.getLocCode());
//        tv_depart.setText(irrBDDeviceDetail.getAdminDept().trim());
//        tv_manager.setText(irrBDDeviceDetail.getAdminName().trim());
//        tv_price.setText(irrBDDeviceDetail.getDevPrice()+"");
//        if (irrBDDeviceDetail.getPurchaseDate() != null)
//        tv_purch.setText(TimeUtil.timestamp2Format(irrBDDeviceDetail.getPurchaseDate().getTimeInMillis()));
//        if (irrBDDeviceDetail.getInstallDate() != null)
//        tv_install.setText(TimeUtil.timestamp2Format(irrBDDeviceDetail.getInstallDate().getTimeInMillis()));
//        tv_remark.setText(irrBDDeviceDetail.getRemark());


        return convertView;
    }

    class ViewHolder
    {
        TextView tv_deviceName ;
        TextView tv_devtype;
        TextView tv_manufac;
        TextView tv_state ;
        TextView tv_loc ;
    }
}
